<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>ArrayUtil</title>
</head>
<body>

</body>
<script src="../../../lib/baitu.min.js"></script>
<script>
    console.log(Baitu)
    const {ArrayUtil} = Baitu;
    console.log(ArrayUtil)
    const res = ArrayUtil.repeat(['a', 1, 'c'], 3);
    console.log(res);

    const finalItem = ArrayUtil.finalItem(['a', "sa", "", () => {}, 3]);
    console.log(finalItem)

    const finalItem2 = ArrayUtil.finalItem([], 2);
    console.log(finalItem2)

    let arr = null;
    arr = ArrayUtil.push(arr, 2);
    console.log(arr);

    console.log(ArrayUtil.isEmpty(arr))
    console.log(ArrayUtil.isEmpty([]))
    console.log(ArrayUtil.isEmpty(null))
    console.log(ArrayUtil.isEmpty(undefined))

    console.log(ArrayUtil.defaultIfEmpty([], [1]))
    console.log(ArrayUtil.defaultIfEmpty(null, [2]))
    console.log(ArrayUtil.defaultIfEmpty(undefined, [3]))
    console.log(ArrayUtil.defaultIfEmpty(arr, [4]))

    console.log('--------------fixedUnshift')
    let arr2 = [2, 3]
    console.log(ArrayUtil.fixedUnshift(arr2, 3, 4, 5, 6))
    console.log(arr2)

    console.log('--------------fixedPush')
    let arr3 = [2, 3]
    console.log(ArrayUtil.fixedPush(arr3, 3, 4, 5, 6))
    console.log(arr3)

    const arr4 = [{
        name: '1',
        age: 23,
        h: 150
    }, {
        name: '2',
        age: 20,
        h: 160
    }, {
        name: '3',
        age: 23,
        h: 178
    }, {
        name: '4',
        age: 25,
        h: 160
    }, {
        name: '5',
        age: 20,
        h: 180
    }]
    console.log("-----------unique")
    console.log(ArrayUtil.unique(arr4, (item) => item.age))
    console.log(ArrayUtil.unique([2, 5, 6, 1, 3, 2, 5]));

    console.log("------------intersection")
    console.log(ArrayUtil.intersection([2, 5, 6, 1, 3, 2, 5], [2, 5, 40, 6, 1, 3, 21, ]))

    console.log("-----------------------union")
    console.log(ArrayUtil.union([2, 5, 6, 1, 3, 2, 5], [2, 5, 40, 6, 1, 3, 21, ]))

    console.log("------------------difference")
    console.log(ArrayUtil.difference([2, 5, 6, 1, 3, 2, 60, 5], [2, 5, 40, 6, 1, 3, 21, ]))

    console.log("---------------groupBy")
    console.log(ArrayUtil.groupBy(arr4, item => item.age))

    console.log("------------orderby")
    console.log(ArrayUtil.orderBy(arr4, ["age asc", "h desc"]))
    console.log(ArrayUtil.orderByDesc(arr4, "age"))
    console.log(ArrayUtil.orderByAsc(arr4, "age"))
    console.log(ArrayUtil.orderByAsc(arr4, "name"))
    console.log(ArrayUtil.orderByDesc(arr4, "name"))
    console.log(ArrayUtil.orderByDesc(arr4))

    console.log("---------------findIndex")
    const arr5 = ["2", "a", "ds", "6", "12"]
    const arr6 = ["a", "a", "ds", "6", "12"]
    console.log(ArrayUtil.findIndex(arr5, 3))
    console.log(ArrayUtil.findIndex(arr6, 3))
    console.log(ArrayUtil.findIndex(arr6, "c"))
    console.log("arr4")
    console.log(ArrayUtil.findIndex(arr4, "2", (item) => item.name))
    console.log(ArrayUtil.findIndex(arr4, "24", (item) => item.age))
</script>
</html>
